﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class standard
    {
        public static void TheManufacturerBlock(Dictionary<string, Object> data)  //制造商模块
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //参数
            string drawdesc = Convert.ToString(data["drawdesc"]);
            string idofframe = Convert.ToString(data["idofframe"]);
            string nameofframe = Convert.ToString(data["nameofframe"]);
            string path = Convert.ToString(data["path"]);
            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(160, 0);
            Vector2 v3 = new Vector2(v2.X, 45);
            Vector2 v4 = new Vector2(0, v3.Y);
            Vector2 v5 = new Vector2(0, 15);
            Vector2 v6 = new Vector2(43, v5.Y);
            Vector2 v7 = new Vector2(v6.X, v4.Y);
            Vector2 v8 = new Vector2(82, v7.Y);
            Vector2 v9 = new Vector2(v8.X, v6.Y);
            Vector2 v10 = new Vector2(v9.X+39, v9.Y);
            Vector2 v11 = new Vector2(v10.X, v8.Y);
            Vector2 v12 = new Vector2(v3.X, v10.Y);
            Vector2 v13 = new Vector2(v12.X, v12.Y+10);
            Vector2 v14 = new Vector2(v6.X, v13.Y);
            Vector2 v15 = new Vector2(v14.X, v14.Y+10);
            Vector2 v16 = new Vector2(v3.X, v15.Y);
            //线段
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v3 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v3, v4 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v4, v1 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            Vector2[] Line6 = { v5, v12 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line7 = { v6, v7 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v9 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line10 = { v11, v10 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { v13, v14 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { v15, v16 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            //定位
            fun.writetext(dxf, "图描述", new Vector2(v7.X + 1, (v7.Y + v15.Y) / 2.0 + 1.75), 3.5, 0, 0.6, "L");
            fun.writetext(dxf, "ID", new Vector2(v7.X + 1, (v14.Y + v15.Y) / 2.0 + 1.75), 3.5, 0, 0.6, "L");
            fun.writetext(dxf, "name", new Vector2(v7.X + 1, (v6.Y + v14.Y) / 2.0 + 1.75), 3.5, 0, 0.6, "L");
            fun.writetext(dxf, drawdesc, new Vector2(v8.X + 1, (v7.Y + v15.Y) / 2.0 + 1.75), 3.5, 0, 0.5, "L");
            fun.writetext(dxf, idofframe, new Vector2(v8.X + 1, (v14.Y + v15.Y) / 2.0 + 1.75), 3.5, 0, 0.5, "L");
            fun.writetext(dxf, nameofframe, new Vector2(v8.X + 1, (v6.Y + v14.Y) / 2.0 + 1.75), 3.5, 0, 0.5, "L");
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}